home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / layout / nsBidiPresUtils.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  11KB  |  277 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is mozilla.org code.
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * IBM Corporation.
  20.  * Portions created by the Initial Developer are Copyright (C) 2000
  21.  * the Initial Developer. All Rights Reserved.
  22.  *
  23.  * Contributor(s):
  24.  *   IBM Corporation
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  28.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. #ifdef IBMBIDI
  41.  
  42. #ifndef nsBidiPresUtils_h___
  43. #define nsBidiPresUtils_h___
  44.  
  45. #include "nsVoidArray.h"
  46. #include "nsIFrame.h"
  47. #include "nsBidi.h"
  48. #include "nsBidiUtils.h"
  49. #include "nsCOMPtr.h"
  50. #include "nsDataHashtable.h"
  51.  
  52. /**
  53.  * A structure representing a logical position which should be resolved
  54.  * into its visual position during BiDi processing.
  55.  */
  56. struct nsBidiPositionResolve
  57. {
  58.   // [in] Logical index within string.
  59.   PRInt32 logicalIndex;
  60.   // [out] Visual index within string.
  61.   // If the logical position was not found, set to kNotFound.
  62.   PRInt32 visualIndex;
  63.   // [out] Visual position of the character, from the left (on the X axis), in twips.
  64.   // Eessentially, this is the X position (relative to the rendering context) where the text was drawn + the font metric of the visual string to the left of the given logical position.
  65.   // If the logical position was not found, set to kNotFound.
  66.   PRInt32 visualLeftTwips;
  67. };
  68.  
  69. class nsBidiPresUtils {
  70. public:
  71.   nsBidiPresUtils();
  72.   ~nsBidiPresUtils();
  73.   PRBool IsSuccessful(void) const;
  74.   
  75.   /**
  76.    * Make Bidi engine calculate the embedding levels of the frames that are
  77.    * descendants of a given block frame.
  78.    *
  79.    * @param aPresContext         The presContext
  80.    * @param aBlockFrame          The block frame
  81.    * @param aFirstChild          The first child frame of aBlockFrame
  82.    * @param aForceReflow         [OUT] Set if we delete frames and will need to
  83.    *                                   reflow the block frame
  84.    * @param aIsVisualFormControl [IN]  Set if we are in a form control on a
  85.    *                                   visual page.
  86.    *                                   @see nsHTMLReflowState::IsBidiFormControl
  87.    *
  88.    *  @lina 06/18/2000
  89.    */
  90.   nsresult Resolve(nsPresContext* aPresContext,
  91.                    nsIFrame*       aBlockFrame,
  92.                    nsIFrame*       aFirstChild,
  93.                    PRBool&         aForceReflow,
  94.                    PRBool          aIsVisualFormControl);
  95.  
  96.   /**
  97.    * Reorder this line using Bidi engine.
  98.    * Update frame array, following the new visual sequence.
  99.    * 
  100.    * @lina 05/02/2000
  101.    */
  102.   void ReorderFrames(nsPresContext*      aPresContext,
  103.                      nsIRenderingContext* aRendContext,
  104.                      nsIFrame*            aFirstChild,
  105.                      nsIFrame*            aNextInFlow,
  106.                      PRInt32              aChildCount);
  107.  
  108.   /**
  109.    * Format Unicode text, taking into account bidi capabilities
  110.    * of the platform. The formatting includes: reordering, Arabic shaping,
  111.    * symmetric and numeric swapping, removing control characters.
  112.    *
  113.    * @lina 06/18/2000 
  114.    */
  115.   nsresult FormatUnicodeText(nsPresContext* aPresContext,
  116.                              PRUnichar*      aText,
  117.                              PRInt32&        aTextLength,
  118.                              nsCharType      aCharType,
  119.                              PRBool          aIsOddLevel,
  120.                              PRBool          aIsBidiSystem);
  121.  
  122.   /**
  123.    * Reorder Unicode text, taking into account bidi capabilities of the
  124.    * platform. The reordering includes symmetric swapping and removing
  125.    * control characters.
  126.    */
  127.   nsresult ReorderUnicodeText(PRUnichar*      aText,
  128.                               PRInt32&        aTextLength,
  129.                               nsCharType      aCharType,
  130.                               PRBool          aIsOddLevel,
  131.                               PRBool          aIsBidiSystem);
  132.  
  133.   /**
  134.    * Return our nsBidi object (bidi reordering engine)
  135.    */
  136.   nsresult GetBidiEngine(nsBidi** aBidiEngine);
  137.  
  138.   /**
  139.    * Reorder plain text using the Unicode Bidi algorithm and send it to
  140.    * a rendering context for rendering.
  141.    *
  142.    * @param[in] aText  the string to be rendered (in logical order)
  143.    * @param aLength the number of characters in the string
  144.    * @param aBaseDirection the base direction of the string
  145.    *  NSBIDI_LTR - left-to-right string
  146.    *  NSBIDI_RTL - right-to-left string
  147.    * @param aPresContext the presentation context
  148.    * @param aRenderingContext the rendering context
  149.    * @param aX the x-coordinate to render the string
  150.    * @param aY the y-coordinate to render the string
  151.    * @param[in,out] aPosResolve array of logical positions to resolve into visual positions; can be nsnull if this functionality is not required
  152.    * @param aPosResolveCount number of items in the aPosResolve array
  153.    */
  154.   nsresult RenderText(const PRUnichar*     aText,
  155.                       PRInt32              aLength,
  156.                       nsBidiDirection      aBaseDirection,
  157.                       nsPresContext*      aPresContext,
  158.                       nsIRenderingContext& aRenderingContext,
  159.                       nscoord              aX,
  160.                       nscoord              aY,
  161.                       nsBidiPositionResolve* aPosResolve = nsnull,
  162.                       PRInt32              aPosResolveCount = 0);
  163.  
  164. private:
  165.   /**
  166.    *  Create a string containing entire text content of this block.
  167.    *
  168.    *  @lina 05/02/2000
  169.    */
  170.   void CreateBlockBuffer(nsPresContext* aPresContext);
  171.  
  172.   /**
  173.    * Set up an array of the frames after splitting frames so that each frame has
  174.    * consistent directionality. At this point the frames are still in logical
  175.    * order
  176.    */
  177.   nsresult InitLogicalArray(nsPresContext* aPresContext,
  178.                             nsIFrame*       aCurrentFrame,
  179.                             nsIFrame*       aNextInFlow,
  180.                             PRBool          aAddMarkers = PR_FALSE);
  181.   /**
  182.    * Reorder the frame array from logical to visual order
  183.    *
  184.    * @param aPresContext the presentation context
  185.    * @param aBidiEnabled TRUE on return if the visual order is different from
  186.    *                      the logical order
  187.    */
  188.   nsresult Reorder(nsPresContext* aPresContext,
  189.                    PRBool&         aBidiEnabled);
  190.   
  191.   /**
  192.    *  Adjust frame positions following their visual order
  193.    *
  194.    *  @param  <code>nsPresContext*</code>, the first kid
  195.    *
  196.    *  @lina 04/11/2000
  197.    */
  198.   void RepositionInlineFrames(nsPresContext*      aPresContext,
  199.                               nsIRenderingContext* aRendContext,
  200.                               nsIFrame*            aFirstChild,
  201.                               PRInt32              aChildCount) const;
  202.   
  203.   void RepositionContainerFrame(nsPresContext* aPresContext,
  204.                                 nsIFrame*       aContainer,
  205.                                 PRInt32&        aMinX,
  206.                                 PRInt32&        aMaxX) const;
  207.   /**
  208.    * Helper method for Resolve()
  209.    * Truncate a text frame and possibly create a continuation frame with the
  210.    * remainder of its content.
  211.    *
  212.    * @param aPresContext the pres context
  213.    * @param aContent     the content of the frame
  214.    * @param aFrame       the original frame
  215.    * @param aNewFrame    [OUT] the new frame that was created
  216.    * @param aFrameIndex  [IN/OUT] index of aFrame in mLogicalFrames
  217.    *
  218.    * If there is already a bidi continuation for this frame in mLogicalFrames,
  219.    * no new frame will be created. On exit aNewFrame will point to the existing
  220.    * bidi continuation and aFrameIndex will contain its index.
  221.    * @see Resolve()
  222.    * @see RemoveBidiContinuation()
  223.    */
  224.   PRBool EnsureBidiContinuation(nsPresContext* aPresContext,
  225.                                 nsIContent*     aContent,
  226.                                 nsIFrame*       aFrame,
  227.                                 nsIFrame**      aNewFrame,
  228.                                 PRInt32&        aFrameIndex);
  229.  
  230.   /**
  231.    * Helper method for Resolve()
  232.    * Delete one or more bidi continuation frames created in a previous reflow by
  233.    * EnsureBidiContinuation().
  234.    * @param aPresContext the pres context
  235.    * @param aFrame       the frame whose continuations are to be removed
  236.    * @param aFirstIndex  index of aFrame in mLogicalFrames
  237.    * @param aLastIndex   index of the last frame to be removed
  238.    * @param aOffset      [OUT] count of directional frames removed. Since
  239.    *                     directional frames have control characters
  240.    *                     corresponding to them in mBuffer, the pointers to
  241.    *                     mBuffer in Resolve() will need to be updated after
  242.    *                     deleting the frames.
  243.    *
  244.    * @see Resolve()
  245.    * @see EnsureBidiContinuation()
  246.    */
  247.   void RemoveBidiContinuation(nsPresContext* aPresContext,
  248.                               nsIFrame*       aFrame,
  249.                               PRInt32         aFirstIndex,
  250.                               PRInt32         aLastIndex,
  251.                               PRInt32&        aOffset) const;
  252.   void CalculateCharType(PRInt32& aOffset,
  253.                          PRInt32  aCharTypeLimit,
  254.                          PRInt32& aRunLimit,
  255.                          PRInt32& aRunLength,
  256.                          PRInt32& aRunCount,
  257.                          PRUint8& aCharType,
  258.                          PRUint8& aPrevCharType) const;
  259.   
  260.   void StripBidiControlCharacters(PRUnichar* aText,
  261.                                   PRInt32&   aTextLength) const;
  262.   nsAutoString    mBuffer;
  263.   nsVoidArray     mLogicalFrames;
  264.   nsVoidArray     mVisualFrames;
  265.   nsDataHashtable<nsISupportsHashKey, PRInt32> mContentToFrameIndex;
  266.   PRInt32         mArraySize;
  267.   PRInt32*        mIndexMap;
  268.   PRUint8*        mLevels;
  269.   nsresult        mSuccess;
  270.  
  271.   nsBidi*         mBidiEngine;
  272. };
  273.  
  274. #endif /* nsBidiPresUtils_h___ */
  275.  
  276. #endif // IBMBIDI
  277.